<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="http://java.sun.com/jsp/jstl/core"%>

<%@ include file="../../../../header.jsp"%>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link
	href="<%=basePath%>statics/resources/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css"
	rel="stylesheet">
<link href="<%=basePath%>bootstrap/css/bootstrap.min.css"
	rel="stylesheet">

<script
	src="<%=basePath%>statics/resources/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="<%=basePath%>bootstrap/js/bootstrap.min.js"></script>
<script
	src="<%=basePath%>statics/resources/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
</head>
<body style="align: center;">
	<div style="margin-top: 10px; margin-left: 30px;">
		<form id="manage-form" action="" class="nice-validator n-yellow"
			novalidate="novalidate" _lpchecked="1">

			<div id="base-form">
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">员工姓名</label>
						</div>
						<div class="ctn-wrap">
                            <input type="text" disabled="disabled" id = "personName" />
						</div>
					</li>
				</ul>
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">合同类型</label>
						</div>
						<div class="ctn-wrap">

							<select style="width: 210px; height: auto;" class="ui-input"
								name="personId" id="contractType">
								<option value="0">试用期合同</option>
								<option value="1">转正合同</option>
							</select>
						</div>
					</li>
				</ul>

				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">开始时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="startTime" id="startTime"
								type="text">
						</div>
					</li>
				</ul>
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">结束时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="endTime" id="endTime"
								autocomplete="off" aria-required="true" type="text">
						</div>
					</li>
				</ul>
				
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">入职时间</label>
						</div>
						<div class="ctn-wrap">
							<input value="" class="ui-input" name="officeDate" id="officeDate"
								autocomplete="off" aria-required="true" type="text">
						</div>
					</li>
				</ul>
				
				<ul class="mod-form-rows base-form cf new-liclass">
					<li class="row-item  no_padding">
						<div class="label-wrap">
							<label for="barCode">当前合同</label>
						</div>
						<div class="ctn-wrap" id="active">
							<input  class="switch-simple-3" id="switch_active" type="checkbox" ><label for="switch_active" class="green"></label>
						</div>
					</li>
				</ul>
			</div>
		</form>
	</div>

	<script type="text/javascript">
		function initDate(startDateTimeId, endDateTimeId ,officeDateTimeId) {
			var startDate;
			var endDate;
			startDateTimeId = "#" + startDateTimeId;
			endDateTimeId = "#" + endDateTimeId;
			officeDateTimeId = "#" + officeDateTimeId;
			$(startDateTimeId).datetimepicker({
				format : 'yyyy-mm-dd hh:ii:ss',
				language : "zh-CN",
				todayHighlight : true,
				autoclose : true,
				todayBtn : true,
				minDate : 0,
				onChangeDateTime : function(dp, $input) {
					startDate = $(startDateTimeId).val();
				},
				onClose : function(current_time, $input) {
					if (startDate > endDate) {
						$(startDateTimeId).val(endDate);
						startDate = endDate;
					}
				}
			});
			
			$(officeDateTimeId).datetimepicker({
				format : 'yyyy-mm-dd hh:ii:ss',
				language : "zh-CN",
				todayHighlight : true,
				autoclose : true,
				todayBtn : true,
				minDate : 0,
				onChangeDateTime : function(dp, $input) {
					startDate = $(officeDateTimeId).val();
				},
				onClose : function(current_time, $input) {
					if (startDate > endDate) {
						$(officeDateTimeId).val(endDate);
						startDate = endDate;
					}
				}
			});
			
			$(endDateTimeId).datetimepicker({
				format : 'yyyy-mm-dd hh:ii:ss',
				language : "zh-CN",
				autoclose : true,
				todayHighlight : true,
				todayBtn : true,
				onClose : function(current_time, $input) {
					endDate = $(endDateTimeId).val();
					if (startDate > endDate) {
						$(endDateTimeId).val(startDate);
						endDate = startDate;
					}
				}
			});
		}

		var api = frameElement.api;
		var operate = api.data.operate;
		var rowid = api.data.rowid;
		var rowdata = api.data.rowdata;
		var CallBack = api.data.callback;
        
		
		initDate('startTime', 'endTime','officeDate');

		$(function() {
			initPopBtns();
			if (operate == "edit" || operate == "view") {
				$("#personName").val(rowdata.personName);
				if(rowdata.contractType=="转正合同"){
					$("#contractType").val("1");
				}
				else{
					$("#contractType").val("0");
				}
				$("#startTime").val(rowdata.endTime);
				$("#endTime").val(rowdata.endTime);
				$("#officeDate").val(rowdata.officeDate);
				$("#active").html(rowdata.currentContract);
                $(".switch-simple-3").attr("disabled",false);
			}
		})
		function initPopBtns() {
			if ("view" == operate) {
				api.button({
					id : "cancel",
					name : "关闭"
				})
				return;
			}

			var btnname = "add" == operate ? [ "保存", "关闭" ] : [ "确定", "取消" ];

			api.button({
				id : "confirm",
				name : btnname[0],
				focus : true,
				callback : function(e) {
					var contractType = $("#contractType").val();
					var startTime = $("#startTime").val();
					var endTime = $("#endTime").val();
					var officeDate = $("#officeDate").val();
					var active = $("#active input").prop("checked");
					var currentContract;
					if(active==true){
						currentContract=1;
					}
					else{
						currentContract=0;
					}
					var re = true;
						$.ajax({
							url : "/contract/updateContract",
							type : "POST",
							async : false,
							data : {"id":rowid,"contractType":contractType,"startTime":startTime,"endTime":endTime,"officeDate":officeDate,"currentContract":currentContract},
							success : function(data) {
								if (data.status == 200) {
									parent.Public.tips({
										content : "修改成功"
									})
									CallBack();
								} else {
									parent.Public.tips({
										type : 1,
										content : "修改失败:" + data.message
									});
									re = false;
								}
							}
						});
				}
			}, {
				id : "cancel",
				name : btnname[1]
			})
		}
		
		initPopBtns();
	</script>
</body>
</html>